/**
 * VideoStudyRecordService.java
 * com.sftj.datacollect.analytics.service
 * Copyright (c) 2018, 北京科技有限公司版权所有.
*/

package com.sftz.modules.datacollect.analytics.service.Impl;

import java.util.List;

import org.nutz.dao.SqlManager;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;

import com.sftz.modules.datacollect.analytics.service.StudyRecordAService;
import com.sftz.modules.datacollect.dto.AudioStudyDto;
import com.uxuexi.core.db.dao.impl.DbDao;
import com.uxuexi.core.db.util.DbSqlUtil;

public class AudioStudyRecordService implements StudyRecordAService {

	private DbDao dbDao;

	private SqlManager sqlManager;

	public AudioStudyRecordService(DbDao dbDao, SqlManager sqlManager) {
		this.dbDao = dbDao;
		this.sqlManager = sqlManager;
	}

	/**
	 * 获取用户音频学习记录
	 * @Date 2018年5月23日
	 * @author gyp
	 * @param courseId
	 * @param userId
	 */
	public List<AudioStudyDto> getAudioStudyRecordByVid(int courseId, int userId, String audioId) {
		Sql sql = Sqls.create(sqlManager.get("web_get_audio_study_info_byAudioId"));
		sql.setParam("courseId", courseId);
		sql.setParam("userId", userId);
		sql.setParam("audioId", audioId);
		List<AudioStudyDto> lists = DbSqlUtil.query(dbDao, AudioStudyDto.class, sql);
		return lists;
	}

	/**
	 * 获取课程学习的总秒数
	 * @Date 2018年5月31日
	 * @author gyp
	 * @param courseId
	 * @param userId
	 * @return(这里描述每个参数,如果有返回值描述返回值,如果有异常描述异常)
	 */
	public List<AudioStudyDto> getAudioStudyInfo(int courseId, int userId) {
		Sql sql = Sqls.create(sqlManager.get("web_get_audio_study_info"));
		sql.setParam("courseId", courseId);
		sql.setParam("userId", userId);
		List<AudioStudyDto> lists = DbSqlUtil.query(dbDao, AudioStudyDto.class, sql);
		return lists;
	}

	/**
	 * 获取音频的最后一条信息
	 * @Date 2018年6月1日
	 * @author gyp
	 * @param courseId
	 * @param userId
	 * @param audioId
	 */
	public AudioStudyDto getAudioStudyLastInfo(int courseId, int userId, int audioId) {
		Sql sql = Sqls.create(sqlManager.get("web_get_audio_study_lastInfo"));
		sql.setParam("courseId", courseId);
		sql.setParam("userId", userId);
		sql.setParam("audioId", audioId);
		AudioStudyDto dto = DbSqlUtil.fetchEntity(dbDao, AudioStudyDto.class, sql);
		return dto;
	}
}
